package org.glut.cloud.repairRecordManage.service;


import org.glut.cloud.repairRecordManage.MaintenanceRecordsdto.Friends;
import org.glut.cloud.repairRecordManage.MaintenanceRecordsdto.Messages;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@Service
public class FriendService {

    @Autowired
    private RestTemplate restTemplate;

    private final String FRIENDS_SERVICE_URL = "http://friends-service"; // 修改为实际服务的 URL

    public List<Friends> getFriends(Integer userId) {
        String url = FRIENDS_SERVICE_URL + "/friends/list?userId=" + userId;
        return restTemplate.getForObject(url, List.class);
    }

    public String addFriend(Integer userId, Integer friendId) {
        String url = FRIENDS_SERVICE_URL + "/friends/add?userId=" + userId + "&friendId=" + friendId;
        return restTemplate.postForObject(url, null, String.class);
    }

    public String deleteFriend(Integer userId, Integer friendId) {
        String url = FRIENDS_SERVICE_URL + "/friends/delete?userId=" + userId + "&friendId=" + friendId;
        return restTemplate.exchange(url, HttpMethod.DELETE, null, String.class).getBody();
    }

    public String sendMessage(Integer senderId, Integer receiverId, String content) {
        String url = FRIENDS_SERVICE_URL + "/messages/send?senderId=" + senderId + "&receiverId=" + receiverId + "&content=" + content;
        return restTemplate.postForObject(url, null, String.class);
    }

    public List<Messages> getMessages(Integer senderId, Integer receiverId) {
        String url = FRIENDS_SERVICE_URL + "/messages/list?senderId=" + senderId + "&receiverId=" + receiverId;
        return restTemplate.getForObject(url, List.class);
    }
}
